import unittest
import allure
from time import sleep

import pytest

from base import base
from airtest.core.api import *
from airtest.core.android import Android
from poco.drivers.android.uiautomation import AndroidUiautomationPoco

poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False)

auto_setup(__file__)

@allure.feature("测试开始")
class TestZhiXue(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        start_app('com.klcxkj.zqxy')
        sleep(5)

    # @classmethod
    # def tearDownClass(cls) -> None:
    #     stop_app('com.klcxkj.zqxy')
    @allure.story("测试用例1")
    @classmethod
    def test_001(self):
        """进行登录操作"""
    try:
        #输入手机号
        poco(name="com.klcxkj.zqxy:id/login_one_phone").set_text("13512345678")
        sleep(4)
        #输入密码
        poco(name="com.klcxkj.zqxy:id/login_one_pass").set_text('q1234567')
        sleep(4)
        #登陆
        poco(name="com.klcxkj.zqxy:id/login_btn").click()
        sleep(4)
        base.arify_element_exist("com.klcxkj.zqxy:id/main_home")
    except Exception as e:
       print(e)

    @allure.story("测试用例5")
    @classmethod
    def test_005(self):
        """进行使用码设置"""
        #进入钱包界面
        poco(name="com.klcxkj.zqxy:id/main_wallet").click()
        sleep(4)
        #进入客服界面
        poco(name="com.klcxkj.zqxy:id/main_service").click()
        base.arify_element_exist("com.klcxkj.zqxy:id/main_home")

    @allure.story("测试用例2")
    @classmethod
    def test_002(self):
        """进行使用码设置"""
    try:
        #进入我的模块
        poco(name="com.klcxkj.zqxy:id/main_mine").click()
        sleep(2)
        #点击使用码
        poco(text="使用码设置").click()
        sleep(4)
        #修改使用码
        poco(text="忘记使用码").click()
        sleep(4)
        #输入密码
        poco(name="com.klcxkj.zqxy:id/code_setting_code_et").set_text("12490")
        sleep(2)
        #确认输入
        poco(name="com.klcxkj.zqxy:id/code_setting_code_again_et").set_text("12490")
        #提交
        poco(name="com.klcxkj.zqxy:id/code_setting_submit_btn").click()
        sleep(3)
    except Exception as e:
       print(e)

    @allure.story("测试用例3")
    @classmethod
    def test_003(self):
        """修改个人信息"""
    try:
        #返回
        keyevent("KEYCODE_BACK")
        #进入完善信息模块
        poco(name="com.klcxkj.zqxy:id/my_quzhi_layout").click()
        #输入姓名
        poco(name="com.klcxkj.zqxy:id/my_name_txt").set_text("ss")
        sleep(4)
        #输入性别
        poco(name="com.klcxkj.zqxy:id/man_Button").click()
        sleep(4)
        #输入证件号
        poco(name="com.klcxkj.zqxy:id/my_idcard_txt").set_text("14567")
        sleep(4)
        #提交
        poco(name="com.klcxkj.zqxy:id/save_btn").click()

    except Exception as e:
       print(e)

    @allure.story("测试用例4")
    @classmethod
    def test_004(self):
        """进行修改密码操作"""
        # 点击设置
        poco(name="趣智校园").click()
        sleep(4)
        # 修改密码
        poco(name="趣智校园 ").click()
        sleep(4)
        # 输入旧密码
        poco(name="com.klcxkj.zqxy:id/pass_old").set_text("q1234567")
        sleep(4)
        #输入新密码
        poco(name="com.klcxkj.zqxy:id/pass_new").set_text("m1234567")
        sleep(4)
        #确认密码
        poco(name="com.klcxkj.zqxy:id/pass_new_confirm").set_text("m1234567")
        sleep(4)
        poco(name="com.klcxkj.zqxy:id/pass_save").click()

    @allure.story("测试用例7")
    @classmethod
    def test_007(self):
        keyevent("KEYCODE_HOME")
        sleep(4)
        #进入客服页面
        poco(name="com.klcxkj.zqxy:id/main_service").click()
        sleep(2)
        #点击故障报修
        poco(text="故障报修").click()
        sleep(3)
        #继续报修
        poco(name="com.klcxkj.zqxy:id/button2").click()
        sleep(4)
        #选择故障类型
        poco(text="洗澡").click()
        sleep(4)
        #输入描述
        poco(name="com.klcxkj.zqxy:id/repair_edit").set_text("123")
        sleep(2)
        #提交
        poco(name="com.klcxkj.zqxy:id/repair_submit_btn").click()
        sleep(3)

    @allure.story("测试用例8")
    @classmethod
    def test_008(self):
        keyevent("KEYCODE_HOME")
        sleep(4)
        # 进入客服页面
        poco(name="com.klcxkj.zqxy:id/main_service").click()
        sleep(2)
        # 点击故障报修
        poco(text="故障报修").click()
        sleep(3)
        # 继续报修
        poco(name="com.klcxkj.zqxy:id/button2").click()
        sleep(4)
        # 选择故障类型
        poco(text="洗澡").click()
        sleep(4)
        # 输入描述
        poco(name="com.klcxkj.zqxy:id/repair_edit").set_text("123")
        sleep(2)
        # 提交
        poco(name="com.klcxkj.zqxy:id/repair_submit_btn").click()
        sleep(3)

    @allure.story("测试用例9")
    @classmethod
    def test_009(self):
        """取消申诉"""
        keyevent("KEYCODE_HOME")
        sleep(4)
        # 进入客服页面
        poco(name="com.klcxkj.zqxy:id/main_service").click()
        sleep(2)
        # 点击待接单
        poco(text="待接单").click()
        sleep(3)
        # 取消订单
        poco(name="com.klcxkj.zqxy:id/order_received_cancel_btn").click()
        sleep(4)

    @allure.story("测试用例10")
    @classmethod
    def test_010(self):
        """进入常见问题界面"""
        keyevent("KEYCODE_HOME")
        sleep(4)
        # 进入客服页面
        poco(name="com.klcxkj.zqxy:id/main_service").click()
        sleep(2)
        # 进入常见问题界面
        poco(name="com.klcxkj.zqxy:id/service_more_question_iv").click()

    @allure.story("测试用例11")
    @classmethod
    def test_011(self):
        """进入申请退款界面"""
        # 进入钱包
        poco(name="com.klcxkj.zqxy:id/main_wallet").click()
        sleep(2)
        # 进入申请退款
        poco(name="com.klcxkj.zqxy:id/money_refund_tv").click()
        sleep(4)

    @allure.story("测试用例12")
    @classmethod
    def test_012(self):
        """进入充值界面"""
        # 进入钱包
        poco(name="com.klcxkj.zqxy:id/main_wallet").click()
        sleep(2)
        # 进入充值界面
        poco(name="com.klcxkj.zqxy:id/card_use_rechange").click()
        sleep(4)

    @allure.story("测试用例13")
    @classmethod
    def test_013(self):
        """进入我的账单"""
        # 进入我的
        poco(name="com.klcxkj.zqxy:id/main_mine").click()
        sleep(2)
        # 进入我的账单界面
        poco(text="我的账单").click()
        sleep(3)
        #点击类型
        poco(name="com.klcxkj.zqxy:id/bill_tv_type").click()
        sleep(4)
        #选择消费类型
        poco(name="com.klcxkj.zqxy:id/pop_list_item_name").click()
        sleep(4)









if __name__ == '__main__':
    pytest.main(['TestCase/test_search.py', '--alluredir', './allure'])
    os.system('allure serve allure')